const express = require('express');
const app = express();
const router = require('./router');

//引入中间件让req.body以对象格式显示
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

// 设置响应头允许跨域请求
app.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  res.header('Access-Control-Allow-Methods', '*');
  res.header('Referrer-Policy', 'strict-origin-when-cross-origin');
  res.header('Content-Type', 'application/json;charset=utf-8');
  next();
});

// 路由
app.use(router)

app.listen(3000, () => {
  console.log('服务已启动，端口：3000');
})
